package com.onlinefurnitureshop.management.service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.onlinefurnitureshop.management.dao.RoleDao;
import com.onlinefurnitureshop.management.model.Role;
import com.onlinefurnitureshop.management.service.ResourceService;
import com.onlinefurnitureshop.management.service.RoleService;

public class RoleServiceImpl implements RoleService{
	
	private RoleDao roleDao;
	
	private ResourceService resourceService;
	
	
	

	public ResourceService getResourceService() {
		return resourceService;
	}

	public void setResourceService(ResourceService resourceService) {
		this.resourceService = resourceService;
	}

	public RoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}

	@Override
	public Role createRole(Role role) {
		// TODO Auto-generated method stub
		return roleDao.createRole(role);
	}

	@Override
	public Role updateRole(Role role) {
		// TODO Auto-generated method stub
		return roleDao.updateRole(role);
	}

	@Override
	public void deleteRole(Long roleId) {
		// TODO Auto-generated method stub
		roleDao.deleteRole(roleId);
	}

	@Override
	public Role findOne(Long roleId) {
		// TODO Auto-generated method stub
		return roleDao.findOne(roleId);
	}

	@Override
	public List<Role> findAll() {
		// TODO Auto-generated method stub
		return roleDao.findAll();
	}

	@Override
	public Set<String> findPersmissions(Long roleId) {
		// TODO Auto-generated method stub
		Set<Long> resourceIds = new HashSet<Long>();
		Role role = findOne(roleId);
		if(role==null)
			return null;
		resourceIds.addAll(role.getResourceIdsList());
		return resourceService.findPermission(resourceIds);
	}
	
}
